/**
 * 
 */
package com.dsteiner.xelavos.client;

import com.dsteiner.widgets.client.FileUploadWidget;
import com.dsteiner.widgets.client.PrefilledPasswordTextBox;
import com.dsteiner.widgets.client.PrefilledTextBox;
import com.dsteiner.widgets.client.Widgets.ButtonExt;
import com.dsteiner.widgets.client.Widgets.HTMLExt;
import com.dsteiner.widgets.client.Widgets.ImageExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.event.EventManagerImpl;
import com.dsteiner.widgets.client.model.FileUploadModel;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.MyProfileController;
import com.dsteiner.xelavos.client.model.AuthenticationModel;
import com.dsteiner.xelavos.client.model.MyProfileModel;
import com.dsteiner.xelavos.client.resources.XelavosImageBundle;
import com.dsteiner.xelavos.client.resources.XelavosResources;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class MyProfileWidget extends LazyWidget{
	private MyProfileController myProfileController = new MyProfileController();
	private MyProfileModel myProfileModel = new MyProfileModel();
	private final AuthenticationModel authenticationModel;
	public MyProfileWidget(AuthenticationModel authenticationModel) {
		this.authenticationModel = authenticationModel;
	}
	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		ImageExt mainImage = new ImageExt();
		ImageExt userNotAvailableImage = new ImageExt(
				XelavosImageBundle.Util.getInstance().userNotAvailableSmallImage().createImage());
		FileUploadModel fileUploadModel = new FileUploadModel();
		FileUploadWidget fileUploadWidget = new FileUploadWidget(fileUploadModel);
		fileUploadModel.setMaxFileSize(Constants.MAX_FILE_SIZE);
		fileUploadModel.setTitle("cambiar foto del perfil (archivo con formato jpg o png)");
		ButtonExt changePasswordButton = new ButtonExt("cambiar contraseña");
		PrefilledTextBoxModel passwordTextBoxModel = new PrefilledTextBoxModel();
		PrefilledPasswordTextBox passwordTextBox = new PrefilledPasswordTextBox(passwordTextBoxModel);
		PrefilledTextBoxModel confirmPasswordTextBoxModel = new PrefilledTextBoxModel();
		PrefilledPasswordTextBox confirmPasswordTextBox = new PrefilledPasswordTextBox(confirmPasswordTextBoxModel);
		passwordTextBoxModel.setDefaultText("ingrese la nueva contraseña");
		confirmPasswordTextBoxModel.setDefaultText("repite la nueva contraseña");
		
		mainPanel.add(mainImage);
		mainPanel.add(userNotAvailableImage);
		mainPanel.add(fileUploadWidget);
		mainPanel.add(passwordTextBox);
		mainPanel.add(confirmPasswordTextBox);
		mainPanel.add(changePasswordButton);
		
		setStyleName(XelavosResources.INSTANCE.css().myProfileWidget());
		mainImage.addStyleName(XelavosResources.INSTANCE.css().mainImg());
		passwordTextBox.setWidth("200px");
		confirmPasswordTextBox.setWidth("200px");
		
		myProfileController.registerAuthenticationModel(authenticationModel);
		myProfileController.registerMyProfileWidget(this);
		myProfileController.registerMainImage(mainImage);
		myProfileController.registerUserNotAvailableImage(userNotAvailableImage);
		myProfileController.registerMyProfileModel(myProfileModel);
		myProfileController.registerFileUploadModel(fileUploadModel);
		myProfileController.registerChangePasswordButton(changePasswordButton);
		myProfileController.registerPasswordTextBoxModel(passwordTextBoxModel);
		myProfileController.registerConfirmPasswordTextBoxModel(confirmPasswordTextBoxModel);
		myProfileController.registerEventManager(EventManagerImpl.getInstance());
		return mainPanel;
	}
}